/**
 * 2020 MegaSphere 主体仪表盘
 * 是用在 B 站直播的
 * 
 * @author Zdream
 * @date 2020-08-08
 * @since aurora 0.4.0
 */

function create (context) {
	return {
		template : context.template,
		data : function () {
			return {
				status : null,
				icons : [],
				iconContents : {
					'loadout' : {
						path: 'M2,0h10v8h-2v2h-10v-8h2Z M16,0h10v8h-2v2h-10v-8h2ZM2,12h10v8h-2v2h-10v-8h2Z M16,12h10v8h-2v2h-10v-8h2Z',
						width: 26, height: 22, name: '物品栏',
					},
					'codex' : {
						path: 'M0,0H20V4H18V6H16V8H14V10H12V12H10V14H8V20H18V18H20V24H0Z'
							+ 'M2,2V4H12V2Z M2,6V8H8V6Z M2,10V12H4V10H2Z'
							+ 'M10,16H16V14H18V12H20V10H22V8H24V6H26V4H28V2H26V0H24V2H22V4H20V6H18V8H16V10H14V12H12V14H10Z',
						width: 28, height: 24, name: '资料',
					},
					'navi' : {
						path: 'M8,0H12V4H10V6H8V8H6V10H0V8H2V6H4V4H6V2H8Z'
							+ 'M14,0H18V2H20V4H22V6H24V8H26V10H20V8H18V6H16V4H14Z'
							+ 'M20,12H26V14H24V16H22V18H20V20H18V22H14V18H16V16H18V14H20Z'
							+ 'M0,12H6V14H8V16H10V18H12V22H8V20H6V18H4V16H2V14H0Z'
							+ 'M12,6H14V8H16V10H18V12H16V14H14V16H12V14H10V12H8V10H10V8H12Z',
						width: 26, height: 22, name: '地图',
					},
				}
			}
		},
		props : {
			sid : String,
		},
		methods : {
			onScreenUpdated : function () {
				let status = context.getStatus(this.sid);
				this.status = status;
				if (!status || !status.data) {
					return;
				}

				this.icons = status.data.icons;
			},
			// 事件驱动
			btn : function () {
				// context.sendCommand(this.sid, '??', {??});
			}
		},
		mounted : function () {
			this.onScreenUpdated(); // 更新 chunkWidth
			context.getBus().$on('screen-status-sync-all', this.onScreenUpdated);
			context.getBus().$on('screen-updated', this.onScreenUpdated);
			context.getBus().$on('screen-destroyed', this.onScreenUpdated);
		},
    destroyed : function () {
      context.getBus().$off('screen-status-sync-all', this.onScreenUpdated);
      context.getBus().$off('screen-updated', this.onScreenUpdated);
      context.getBus().$off('screen-destroyed', this.onScreenUpdated);
    }
	};
}

export default create;
